#!usr/bin/python
# -*- coding: UTF-8 -*-

try:
    f = open('data.txt', 'w')
    for each_line in f:
        print(each_line)
except OSError as reason:
    print('出错啦：' + str(reason))
finally:
    f.close()





try:
    with open('data.txt', 'w') as f:
        for each_line in f:
            print(each_line)
except OSError as reason:
    print('出错啦：' + str(reason))
#有了with,就不用手动去关闭文件了, with会关注文件啥时候没有关闭，就自动去关闭了





